package mrms.api.web.controllers;

import lombok.AllArgsConstructor;
import mrms.api.entity.MeetingEntity;
import mrms.api.repository.MeetingRepository;
import mrms.api.web.utils.Result;
import mrms.api.web.utils.TimeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lenchu
 * @date 2019/03/05
 */
@RestController
@AllArgsConstructor
@RequestMapping("/front")
public class FrontController {
    private MeetingRepository meetingRepository;

    @GetMapping("/meeting/{room}/today")
    public Result findTodayMeetings(@PathVariable String room) {
        Long start = TimeUtils.getOneDayZeroPointTimestamps(System.currentTimeMillis());
        Long end = start + 24 * 60 * 60 * 1000;
        List<MeetingEntity> all = meetingRepository.findAllByRoomAndStarttimeBetween(room, start / 1000, end / 1000);
        return Result.success(all);
    }
}
